package com.shine.icis.action;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.IDepotBankInfoService;
import com.shine.icis.config.SysConstants;
import com.shine.icis.dto.DepotBankInfo;
import com.shine.icis.exception.ICISException;
import com.shine.icis.util.EFRameInf;

/**
 * 基础信息管理->证券公司存管银行信息文件
 * @author zsy
 *
 */
public class DepotBankInfoAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7638121893867812633L;
	
	private IDepotBankInfoService depotBankInfoService;
	
	//input param
	private int pageNo;
	private int pageSize;
	private String oldBankCode;
	
	private String bankCode;//银行代码
	private String bankName;//银行名称
	private String occurDate;//
	
	//output param
	private ListPage<DepotBankInfo> depotBankInfoPage;
	
	public void setDepotBankInfoService(IDepotBankInfoService depotBankInfoService) {
		this.depotBankInfoService = depotBankInfoService;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setOldBankCode(String oldBankCode) {
		this.oldBankCode = oldBankCode;
	}

	public void setBankCode(String bankCode) {
		this.bankCode = bankCode;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public void setOccurDate(String occurDate) {
		this.occurDate = occurDate;
	}
	

	public ListPage<DepotBankInfo> getDepotBankInfoPage() {
		return depotBankInfoPage;
	}

	/**
	 * 转到查询页面
	 * @return
	 */
	public String initQueryDepotBankInfo() {
//		companyCode = companyInfoService.getCompanyCode();
		return success();
	}
	
	/**
	 * 查询
	 * @return
	 */
	public String queryDepotBankInfo() {
		QueryParameters qp = new QueryParameters();
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		try {
			depotBankInfoPage = depotBankInfoService.getDeptInfoPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	
	/**
	 * 新增
	 * @return
	 */
	public String addDepotBankInfo() {
		if (bankCode == null || bankCode.trim().equals("")
				|| bankName == null || bankName.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			depotBankInfoService.addDepotBankInfo(bankCode, bankName, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "增加证券公司存管银行信息银行代码为[" + bankCode + "]", success);
		}
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String modifyDepotBankInfo() {
		if (oldBankCode == null || oldBankCode.trim().equals("")
				|| bankCode == null || bankCode.trim().equals("")
				|| bankName == null || bankName.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			depotBankInfoService.modifyDepotBankInfo(oldBankCode, bankCode, bankName, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "修改证券公司存管银行信息银行代码为[" + oldBankCode + "]", success);
		}
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String deleteDepotBankInfo() {
		if (bankCode == null || bankCode.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			depotBankInfoService.deleteDepotBankInfo(bankCode);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "删除证券公司存管银行信息银行代码为[" + bankCode + "]", success);
		}
	}

}
